<template>
 <div class="firstList">
   <h3 class="title">
     <span class="t">通知公告</span>
     <router-link :to="`../list/${itemId}?key=通知公告`">查看更多 <RightOutlined /></router-link>
   </h3>

   <ul class="firstList_body">
     <li v-for="item in ArticleList" :key="item.article_id">
       <a target="_blank" :href="`/articleDetail/${item.article_id}`"> {{ item.article_title }} </a>
<!--       <a target="_blank" :href="`../article/${itemId}?id=${item.article_id}`">{{ item.article_title }}</a>-->
       <span>{{ parseTime(item.publish_time) }}</span>
     </li>
   </ul>
   <div class="pt80" v-if="requestComplete && ArticleList.length===0">
     <Empty description="暂无数据"/>
   </div>
 </div>
</template>

<script lang="ts" >
import {defineComponent, inject, onMounted, ref } from "vue";
import { Row, Col , Empty } from "ant-design-vue";
import { RightOutlined } from '@ant-design/icons-vue';
import { parseTime , findOneDataObj } from '/@/utils';
import {getArticleListApi, getItemTreeApi} from "/@/api/theme";

export default defineComponent({
  name: "firstList",
  components: { Row, Col , RightOutlined , Empty},

  setup() {

    const itemId = inject('itemId') as string;
    const ArticleList = ref([]);
    const requestComplete = ref(false);
    const getItemTree = async () => {
      const Param = { includeSelf:false,itemId:itemId }
      let { success , data } = await getItemTreeApi(Param);
      if(success){
        let noticeObj = findOneDataObj(data,'通知公告')
        getItemList(noticeObj.data.itemId)
      }
    }

    const getItemList = x => {
      const Param = { current:1,size:6,itemId: x }
      getArticleListApi(Param).then(({ success , data })=>{
        requestComplete.value=true;
         if(success){
           let { total , records } = data;
           if(total) ArticleList.value = records
         }
      })
    }



    const init = () => {
      getItemTree();
    }
    onMounted(init)

    return {
       parseTime , ArticleList , itemId ,requestComplete
    };
  }
});
</script>

<style lang="less" scoped>
.firstList{
  .title{
    border-bottom: 1px solid #E0E5EB;

    span.t{
      display: inline-block;
      padding-bottom: 10px;
      font-size: 20px;
      line-height: 28px;
      border-bottom: 3px solid #2E77D6;
    }

    a{
      float: right;
      font-size: 14px;
      transform: translateY(12px);

      .anticon{
        font-size: 14px;
      }
    }
  }
}

.firstList_body {
  >li  {
    display: flex;
    justify-content: space-between;
    margin-top: 28px;
    font-size: 16px;
    line-height: 20px;
    color: #262626;

    a{
      display: inline-block;
      width: 460px;
      overflow: hidden;
      text-overflow: ellipsis;
      white-space: nowrap;

      &:hover{
        color: @blue;
      }
    }

    >span {
      color: #999;
    }
  }
}

</style>
